﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace GeneratingKeys
{
    class Program
    {
        //private static byte[] 
        static void Main(string[] args)
        {
            Console.WriteLine("Rijndael Key:------------------------");
            GenerateKeys(64);//AES - Rijndael
            Console.WriteLine("SHA1 Key:-------------------------");
            GenerateKeys(128);//Hash- SHA1
            Console.WriteLine("3DES Key:-------------------------");
            GenerateKeys(48);//3DES
            Console.ReadLine();

        }

        /// <summary>
        ///Each byte is represented by two hexadecimal characters; therefore, to request a 32-byte key, 
        ///pass 64 as a command line argument. If you do not specify an argument,  
        ///the code returns a 128 hexadecimal character (64-byte) key.
        ///Recommeded Key Lengths: 
        ///AES: 32 bytes (64 hexadecimal characters).
        ///3DES: 24 bytes (48 hexadecimal characters).
        ///SHA1: 64 bytes (128 hexadecimal characters).
        /// </summary>
        /// <param name="hexCharacters"></param>
        private static void GenerateKeys(int hexCharacters)
        {
            int len = 128;
            if (hexCharacters > 0)
                len = hexCharacters;
            byte[] buff = new byte[len / 2];
            RNGCryptoServiceProvider rng = new
                                    RNGCryptoServiceProvider();
            rng.GetBytes(buff);
            StringBuilder sb = new StringBuilder(len);
            for (int i = 0; i < buff.Length; i++)
                sb.Append(string.Format("{0:X2}", buff[i]));
            Console.WriteLine(sb);
        }
    }
}
